package com;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.TreeMap;

import org.junit.Test;

public class Coliection {

	
	/**
	 *   test   coliection
	 */
	
	@Test
	public void coliection(){
		
		
		/**
		 *  treeMap 性能
		 */
		Map<Integer,Integer> treeMap = new TreeMap<Integer, Integer>();
		
		long  start = System.currentTimeMillis();
		for(int i =0;i<100000;i++){
			treeMap.put(i,i);
		}
		long end = System.currentTimeMillis();
		System.out.println("treeMap存入耗时 ：" + (end - start));
		
		
		Set<Entry<Integer,Integer>> treeSet= treeMap.entrySet();
		Iterator<Entry<Integer, Integer>> ittree = treeSet.iterator();
		
		long a = System.currentTimeMillis();
		List<Integer> list = new ArrayList<Integer>();
		while(ittree.hasNext()){
		    Map.Entry<Integer,Integer> entry = (Map.Entry<Integer, Integer>)ittree.next();
		}
		System.out.println(list.size());
		long b = System.currentTimeMillis();
		System.out.println("====== : " + (b-a));
		
		Map<Integer,Integer> hashMap = new HashMap<Integer, Integer>();
		
		long  hashStart = System.currentTimeMillis();
		for(int i =0;i<100000;i++){
			hashMap.put(i,i);
		}
		long hashEnd = System.currentTimeMillis();
		System.out.println("hashMap存入耗时 ：" + (hashEnd - hashStart));
		
		long  hashStart1 = System.currentTimeMillis();
		Set<Entry<Integer,Integer>> hhmap = hashMap.entrySet();
		Iterator<Entry<Integer, Integer>> hsMap =  hhmap.iterator();
		while(hsMap.hasNext()){
			System.out.println(hsMap.next().getValue());
		}
		long hashEnd1 = System.currentTimeMillis();
		System.out.println("hashMap取出耗时 ：" + (hashEnd1 - hashStart1));
		
		/**
		 *  list 
		 */
		long al = System.currentTimeMillis();
		List<Integer> lists = new ArrayList<Integer>();
		for(int i =0;i<100000;i++){
			lists.add(i);
		}
		long bl = System.currentTimeMillis();
		System.out.println("list put Time :" + (bl-al));
		
		
		long aal = System.currentTimeMillis();
		for(int i =0;i<lists.size();i++){
			lists.get(i);
		}
		long bbl = System.currentTimeMillis();
		System.out.println("list get Time : " + (bbl-aal));
		
		
	}
}
